﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Configuration;
using System.Data.SqlClient;

/// <summary>
/// Summary description for adminstock
/// </summary>
namespace Bestlife.ERP.DataAccess
{
    public class adminstock
    {
        public static int prono;
        public adminstock()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public static List<string> stockchecking()
        {
            List<string> returnlist = new List<string>();
            SqlDataReader rdR;
            try
            {

                DateTime date = System.DateTime.Now;
                String connStr = ConfigurationManager.ConnectionStrings["BestlifeDBConnectionString"].ConnectionString;
                Bestlife.ERP.DataAccess.Connection.connect(connStr);//connection string pass to connection class


                String Ssql = "SELECT [Pro_Name] FROM [Tbl_Stock] where [Qty_in_stock]=[Re_Order_Level]";

                rdR = Connection.ReadTable(Ssql);


                while (rdR.Read())
                {
                    returnlist.Add(rdR["Pro_Name"].ToString());

                }

                rdR.Close();

            }
            catch (Exception)
            {

            }
            Connection.con.Close();
            return returnlist;

        }

        public static List<string> reordercheck()
        {
            List<string> returnlist = new List<string>();
            SqlDataReader rdR;
               SqlDataReader rdR1;
               
               try
               {

                   DateTime date = System.DateTime.Now;
                   String connStr = ConfigurationManager.ConnectionStrings["BestlifeDBConnectionString"].ConnectionString;
                   Bestlife.ERP.DataAccess.Connection.connect(connStr);//connection string pass to connection class
                   String sql1 = "SELECT COUNT(Pro_ID)as product  FROM [BestlifeDB_temp].[dbo].[Tbl_Product]";
                   rdR1 = Connection.ReadTable(sql1);
                   if (rdR1.Read())
                   {
                       prono = int.Parse(rdR1["product"].ToString());
                   }
                   rdR1.Close();
                   for (int i = 0; i < prono; i++)
                   {


                       String Ssql = "SELECT DATEDIFF(day,(SELECT [Date_Create] FROM [Tbl_Product] where [Pro_ID]='" + i + "' and [Code]='1'),(SYSDATETIME()) )as NumberOfDays";

                       rdR = Connection.ReadTable(Ssql);


                       while (rdR. Read())
                       {
                           string noofdays = rdR["NumberOfDays"].ToString();
                           //int f =Convert.ToInt32(noofdays.ToString());
                           returnlist.Add(noofdays);
                           //if (noofdays >= 28)
                           //{
                           //   returnlist.Add(i.ToString());
                              
                           //}

                       }

                       rdR.Close(); 

                   }
               }
               catch (Exception)
               {

               }
            Connection.con.Close();
            return returnlist;

        }

    }
}
